package Java9_16;

public class Work1 implements Runnable{
    public static final Object object1=new Object();
    public static final Object object2=new Object();
    boolean boo;
    @Override
    public void run() {
        if(boo) {
            synchronized (object1) {
                System.out.println("进入1锁");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (object2) {
                    System.out.println("进入2锁");
                }
            }
        }else {
            synchronized(object2) {
                System.out.println("进入2锁");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (object1) {
                    System.out.println("进入1锁");
                }
            }
        }

    }
}
